//定义一个大写的State类型
import { reactive } from 'vue';
import { Goods } from '../vendor/order_food/goods';
import { Category } from '../vendor/order_food/category';
export type State = {
	phone: string;
	servicePhone: string; // 客服电话
	moneyAll: number; // 商家总收款金额(单位分)
	moneyToday: number; // 商家今日收款金额(单位分)
	address: string; // 用户选择位置
	longitude: string; // 用户选择经度
	latitude: string; // 用户选择纬度

	category: Category; // 商户端选择的分类
	goods: Goods; // 商户端选择的商品
};
// 实例化为state
export const state = reactive({
	token: '',
	phone: '',
	servicePhone: '',
	moneyAll: 0,
	moneyToday: 0,
	address: '',
	longitude: '',
	latitude: '',
	category: { id: 0, title: '',sort:0 },
	goods: {
		id: 0,
		title: '',
		img: '',
		category_id: 0,
		status: 1,
		des: '',
        price : 0,
		stock: 0 
	}
} as State);

export const setAddress = (v: string) => {
	state.address = v;
};
export const setLongitude = (v: string) => {
	state.longitude = v;
};
export const setLatitude = (v: string) => {
	state.latitude = v;
};
export const getPhone = () => {
	if (!state.phone) {
		const phone = uni.getStorageSync('phone');
		state.phone = phone;
	}
	return state.phone;
};

export const getServicePhone = () => {
	if (!state.servicePhone) {
		const phone = uni.getStorageSync('servicePhone');
		state.servicePhone = phone;
	}
	return state.servicePhone;
};

export const getMoneyAll = () => {
	if (!state.moneyAll) {
		const v = uni.getStorageSync('moneyAll');

		state.moneyAll = v ? v : 0;
	}
	return state.moneyAll;
};

export const getMoneyToday = () => {
	if (!state.moneyToday) {
		const v = uni.getStorageSync('moneyToday');
		state.moneyToday = v ? v : 0;
	}
	return state.moneyToday;
};

export const setPhone = (phone: string) => {
	state.phone = phone;
	uni.setStorageSync('phone', phone);
};

export const setServicePhone = (phone: string) => {
	state.servicePhone = phone;
	uni.setStorageSync('servicePhone', phone);
};

export const setMoneyAll = (money: number) => {
	state.moneyAll = money;
	uni.setStorageSync('moneyAll', money);
};

export const setMoneyToday = (money: number) => {
	state.moneyToday = money;
	uni.setStorageSync('moneyToday', money);
};
export const setGoods = (goods: Goods) => {
	state.goods = goods;
};
export const setCategory = (category:Category)=>{
	state.category = category
}
